<%@page import="com.crm.util.Pager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资源分配</title>
	<% request.setAttribute("menu", 1); %>
	<meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <%@ include file="/WEB-INF/page/public/contentmeta.jsp"%>
    <link rel="stylesheet" href="<%=basePath%>plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="<%=basePath%>css/global.css" media="all" />
    <link rel="stylesheet" href="<%=basePath%>plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/tab.css" media="all" />
    
    <style type="text/css">
		.trans_tc,.transmore_tc,.transall_tc {display: none;}
		.wybsf p { margin-top: 8px; }
    </style>
    
</head>
<body>

<input type="hidden" id="successlog" value="${successlog}">

<div class="admin-tab admin-user admin-transform">
    <div class="tab-condition">
        <form class="layui-form clefix" action="/customer/customertemplist" method="post" id="transformform">
            <div class="layui-form-item">
            	<input name="skipToPage" id="skipToPage"  type="hidden" value="${pager.pageNo}">
				<input type="hidden" id="pageNo" name="pageNo" value="${pager.pageNo}">
				<input type="hidden" id="totalPage" name="totalPage" value="${pager.totalPages}">
				<input type="hidden" id="pageSize" name="pageSize" value="${pager.pageSize}">
            </div>
        </form>
        <div class="TM-tab-info">
        	<a class="layui-btn layui-btn-primary layui-btn-small active upinfo">上传资源</a>
        	<a class="layui-btn layui-btn-primary layui-btn-small active transall">+全部分配</a>
        	<a class="layui-btn layui-btn-primary layui-btn-small transsome">+部分分配</a>
        	<a class="layui-btn layui-btn-primary layui-btn-small trans">+分配</a>
        	<a class="layui-btn layui-btn-primary layui-btn-small refreshbtn"><i class="layui-icon">&#x1002;</i>刷新</a>
        </div>
    </div>
    <div class="layui-field-box">
        <table class="site-table table-hover TM-user TM-table3">
            <thead>
            <tr>
                <th style="width:5%;"><input type="checkbox" id="selected-all"/></th>
                <th style="width:10%;">姓名</th>
                <th style="width:10%;">联系电话</th>
                <th style="width:10%;">地区</th>
				<th style="width:20%;">证书及专业</th>
				<th style="width:10%;">身份证</th>
				<th style="width:10%">成熟等级</th>
                <th style="width:15%;">操作</th>
            </tr>
            </thead>
            <tbody>
            	<c:forEach var="obj" items="${pager.resultList}">
            		<tr data="${obj.id}">
	            		<td><input type="checkbox" name="select-all-cbox" value="${obj.id}"/></td>
	            		<td>${obj.cname}</td>
	            		<td>${obj.tel}</td>
	            		<td><dic:str value="${obj.address}"  maxLength="6"/> </td>
	            		<td>${obj.technicalpost}</td>
	            		<td data="${obj.id}">${obj.idcard}</td>
	            		<td ><dic:cf value="${obj.state}" name="customer_state" type="1"/></td>
	            		<td>
	            			<a href="#" class="layui-btn layui-btn-normal layui-btn-mini fpbtn">分配</a>
	            			<a href="#" class="layui-btn layui-btn-normal layui-btn-mini delete">删除</a>
	            		</td>
            		</tr>
            	</c:forEach>
            </tbody>
        </table>
        <div class="admin-table-page">
			<div   class="page" ><div class="layui-laypage"  ><span class="layui-laypage-total"><button type="button" class="layui-laypage-btn">共${pager.totalSize}条记录</button></span></div></div>
		</div>
        <div class="admin-table-page">
            <div id="page" class="page"></div>
        </div>
    </div>
    
</div>


<!-- 资源上传弹窗 -->
<div class="upfilediv" style="display: none;">
	<form id="insertform" action="/systerm/upexcelastemp" method="post" enctype="multipart/form-data">
		<div style="margin-top: 20px;font-size: 18px; text-align: center;">
			<div>
				点击下载<a href="<%=basePath%>upload/resume.xlsx"><b>人才模版</b></a>，填写完成后点击上传.
			</div>
			<div style="margin-top: 10px;">
				<input type="file" id="file" name="file" style="border: 1px solid #e6e6e6;height: 31px;">
			</div>
		</div>
	</form>
</div>

<!-- 全部转移 -->
<div class="transall_tc">
	<form action="" id="transall_form"  class="layui-form" >
		<div class="layui-form-item">
        	<label class="layui-form-label">转移给 :</label>
       		<div class="layui-input-inline" >
              		<select name="uid" id="alluids" lay-filter="uids">
					<c:forEach var="nameobj" items="${userlist}">
						<c:if test="${nameobj.uid != pager.params.uid}">
							<option value="${nameobj.uid}">${nameobj.name}</option>
						</c:if>
					</c:forEach>
				</select>
           	</div>
		</div>
	</form>
</div>

<!-- 部分转移 多页转移 -->
<div class="transmore_tc">
	<form action="" id="transmore_form"  class="layui-form" >
		<div class="layui-form-item">
			<label class="layui-form-label"><span>说明 : </span></label>
			<div class="layui-input-inline wybsf">
				<p class="wybsf_p">资源共：${pager.totalPages}页，每页：${pager.pageSize}条</p>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span>起始页数 : </span></label>
			<div class="layui-input-inline">
				<select name="startpage" id="startpage" lay-filter="lay-filter">
					<option value="">请选择</option>
       		 		<c:if test="${pager.totalPages > 1}">
     					<c:forEach begin="0" end="${pager.totalPages-1}" var="objs" varStatus="o1">
     						<option value="${o1.index+1}">${o1.index+1}</option>
     					</c:forEach>
        			</c:if>
           			<c:if test="${pager.totalPages == 1}">
           				<option value="1">1</option>
           			</c:if>
              	</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span>结束页数 : </span></label>
			<div class="layui-input-inline">
				<select name="endpage" id="endpage" lay-filter="lay-filter">
					<option value="">请选择</option>
						<c:if test="${pager.totalPages > 1}">
	                		<c:forEach begin="0" end="${pager.totalPages-1}" var="objs" varStatus="o1">
	                			<option value="${o1.index+1}">${o1.index+1}</option>
	                		</c:forEach>
	               		</c:if>
	               		<c:if test="${pager.totalPages == 1}">
	               			<option value="1">1</option>
	               		</c:if>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">转移给 :</label>
			<div class="layui-input-inline" >
				<select name="uid" id="uidss" lay-filter="uidss">
					<c:forEach var="nameobj" items="${userlist}">
						<option value="${nameobj.uid}">${nameobj.name}</option>
					</c:forEach>
				</select>
			</div>
		</div>
	</form>
</div>


<!-- 转移一个或多个 -->
<div class="trans_tc">
   	<form action="" id="trans_form"  class="layui-form" >
   		<div class="layui-form-item">
            <label class="layui-form-label">转移给 :</label>
            <div class="layui-input-inline" >
				<select name="uid" id="uids" lay-filter="uids">
					<c:forEach var="nameobj" items="${userlist}">
						<c:if test="${nameobj.uid != pager.params.uid}">
							<option value="${nameobj.uid}">${nameobj.name}</option>
						</c:if>
					</c:forEach>
				</select>
             </div>
		</div>
	</form>
</div>


<div class="Mask ZZmask"></div>

<script type="text/javascript">
	layui.use(['icheck','element','laypage','form','laydate'],function(){
		
		var $ = layui.jquery,
		layer = layui.layer,
		laypage = layui.laypage;
		var form = layui.form();
		form.render();
		
		//input的全选与取消全选
        $("#selected-all").on("click",function(){
        	if ($("#selected-all").is(":checked")){
        		$("[name='select-all-cbox']").prop("checked",true);
        	} else {
        		$("[name='select-all-cbox']").prop("checked",false);
        	}
        });
		
		//点击上传资源
		$(".upinfo").on("click",function(){
			layer.open({
        		type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"上传资源",
		  		zIndex: 999,
		  		content: $(".upfilediv"),
		  		area:['70%','50%'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			var type = $("#filetype").val();
		  			$("#insertform").submit();
		  		}
			});
		});
		
		//读取页面的提示信息并展示
	    var successlog = $("#successlog").val();
	    if (successlog != null && successlog.length > 0) {
	    	var html = "<div style='margin-top:10px;margin-left:15px;'><p>" + successlog + "</p></div>"
	    	layer.open({
	    		type: 1, 
	    		title : "资源导入完成",
	    		content: html, 
	    		shadeClose:true,
	    		area: ['40%','90%'],
	    	});
	    }
		
		//点击全部分配
		$(".transall").on("click",function(){
			layer.open({
				type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"资源分配",
		  		zIndex: 999,
		  		content: $(".transall_tc"),
		  		area:['70%','80%'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			//全部分配只要知道分配给谁就行
		  			layer.confirm('确认分配全部资源吗？', {
						btn: ['确定','取消'] //按钮
					}, function(){
						var uid = $("#alluids").val();
						//加载层
		  				var loadindex = layer.load();
		  				$.ajax({
			  				type : "post",
			  				data : {uid : uid},
			  				url : "/customer/distributionall",
			  				dataType : "json",
			  				success : function(data){
			  					//关闭加载层
		  						layer.close(loadindex);
			  					layer.msg("资源分配成功",{icon:1},function(){
			  						window.location.reload();
			  					});
			  				}
			  			});
					}, function(){
					});
		  		}
			});
		});
		
		//点击部分分配
		$(".transsome").on("click",function(){
			layer.open({
				type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"资源分配",
		  		zIndex: 999,
		  		content: $(".transmore_tc"),
		  		area:['70%','80%'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			//部分分配要知道起始页,结束页,分配给谁
		  			var uid = $("#uidss").val();
		  			var startpage = $("#startpage").val();//起始页数
		  			var endpage = $("#endpage").val();//结束页数
		  			var pagesize = $("#pageSize").val(); //每页条数
		  			
		  			if (endpage-totalPage > 0) {
		  				layer.msg("页数输入有误：超出了总页数。")
		  				return false;
		  			}
		  			
		  			if (startpage > endpage) {
		  				layer.msg("页数选择有误：起始页不得大于结束页。")
		  				return false;
		  			}
		  			
		  			layer.confirm('确认分配资源吗？', {
			  			  btn: ['确定','取消'] //按钮
			  		}, function(){
			  			
			  			if (endpage == null || endpage == "") {
			  				layer.msg("请选择结束页数");
			  				return false;
			  			}
			  			
			  			if (startpage == null || startpage == "") {
			  				layer.msg("请选择起始页数");
			  				return false;
			  			}
			  			//加载层
		  				var loadindex = layer.load();
			  			$.ajax({
			  				type : "post",
			  				url : "/customer/distributionsome",
			  				data : {startpage : startpage ,endpage : endpage, uid : uid , pagesize : pagesize },
			  				dataType : "json",
			  				success : function(data){
			  					//关闭加载层
		  						layer.close(loadindex);
		  						layer.msg("资源分配成功",{icon:1},function(){
			  						window.location.reload();
			  					});
			  				}
			  			});
			  		}, function(){
			  		});
		  			
		  		}
			});
		});
		
		//点击头部分配
		$(".trans").on("click",function(){
			
			//看看有哪些被选中的
			var value;
    		//利用.each获取
			$("input:checkbox[name='select-all-cbox']:checked").each(function(i){
				if (i == 0) {
					value = $(this).val();
				} else {
					value += ","+$(this).val();
				}
			});
    		if (value == null || value == '') {
    			layer.msg("请选择一条或多条资源");
    			return false;
    		}
			
			layer.open({
				type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"资源分配",
		  		zIndex: 999,
		  		content: $(".trans_tc"),
		  		area:['40%','60%'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			//分配要知道分配哪几个记录,分配给谁
		  			var uid = $("#uids").val();
		  			layer.confirm('确认分配资源吗？', {
			  			  btn: ['确定','取消'] //按钮
			  			}, function(){
			  				//加载层
			  				var loadindex = layer.load();
			  				$.ajax({
				  				type : "post",
				  				url : "/customer/distributiononeorsome",
				  				data : {uid : uid,cusids : value},
				  				dataType : "json",
				  				success : function(data){
				  					//关闭加载层
			  						layer.close(loadindex);
				  					layer.msg('资源分配成功', {icon: 1,time:700},function(){
				  						layer.load();
				  						window.location.reload();
				  					});
				  				}
				  			});
			  			}, function(){
			  			});
		  		}
			});
		});
		
		//点击单个分配
		$(".fpbtn").on("click",function(){
			//获取id
			var id = $(this).parent().parent().attr("data");
			layer.open({
				type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"资源分配",
		  		zIndex: 999,
		  		content: $(".trans_tc"),
		  		area:['40%','60%'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			//分配要知道分配哪几个记录,分配给谁
		  			var uid = $("#uids").val();
		  			layer.confirm('确认分配资源吗？', {
			  			  btn: ['确定','取消'] //按钮
			  			}, function(){
			  				//加载层
			  				var loadindex = layer.load();
			  				$.ajax({
				  				type : "post",
				  				url : "/customer/distributiononeorsome",
				  				data : {uid : uid,cusids : id},
				  				dataType : "json",
				  				success : function(data){
				  					//关闭加载层
			  						layer.close(loadindex);
				  					layer.msg('资源分配成功', {icon: 1,time:700},function(){
				  						layer.load();
				  						window.location.reload();
				  					});
				  				}
				  			});
			  			}, function(){
			  			});
		  		}
			});
			
		});
		
		//点击删除
		$(".delete").on("click",function(){
			//获取id
			var ids = $(this).parent().parent().attr("data");
			layer.confirm('确定删除？删除后无法恢复', {
				btn: ['确定','取消'] //按钮
  			}, function(){
  				$.ajax({
  					type : "post",
  					data : {ids : ids},
  					url : "/customer/deletecustemp",
  					dataType : "json",
  					success : function(data){
  						layer.msg('删除成功');  
  						window.location.reload();
  					}
  				});
  			}, function(){
  				
  			});
		});
		
		
		
		
		//分页
		var pageNo = $("#pageNo").val();
    	var totalPage = $("#totalPage").val();
    	laypage({
            cont: 'page',
            curr: pageNo//'${pager.pageNo}'
            ,pages: totalPage//'${pager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            skip: true,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) {
                	$("#skipToPage").val(curr);
                	$("#transformform").submit();
                }
            }
        }); 
	});
</script>



</body>
</html>